package dev.alm.serviceweather.controller;

import dev.alm.serviceweather.dto.WeatherDto;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("api/weather")
public class WeatherController {

    @PostMapping("get")
    public String getWeather(@RequestHeader("x-token") String token, @RequestBody WeatherDto weatherDto) {
        Long cityId = weatherDto.getCityId();
        String cityName = weatherDto.getCityName();
        return "token: " + token + ", cityId: " + cityId + ", cityName: " + cityName;
    }

    @GetMapping("test_low_request")
    public String testLowRequest() {
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return "weather service: test low request";
    }

    @GetMapping("req_ex")
    public String reqEx() {
        System.out.println("weather req ex enter");
        int i = 10 / 0;
        return "weather service: req ex";
    }

}
